<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8"/>
<title>Insert title here</title>
</head>
<body> 
    <p><input type="file" id="file1" name="file"/></p>
    <p><input type="button" id="upload" value="上传"/></p> 
    <p><input type="hidden" id="myId" name="id" value="4"/></p>            
</body>
<script src="https://cdn.bootcss.com/jquery/2.0.1/jquery.min.js"></script>
<script type="text/javascript">
/*<![CDATA[*/
 $(function(){
           $("#upload").click(function () {      
        	   var fileObj = document.getElementById("file1").files[0]; // js 获取文件对象
        	   
               if (typeof (fileObj) == "undefined" || fileObj.size <= 0) {
                   alert("请选择图片");
                   return;
               }  
                
               var formFile = new FormData();               
               formFile.append("file", fileObj);   //加入文件对象              
               $.ajax({
                   url: "http://localhost:8080/importWharf",
                   data: formFile,                                 
                   type: "post",
                   dataType: "json",
                   cache: false,//上传文件无需缓存
                   processData: false,//用于对data参数进行序列化处理 这里必须false
                   contentType: false, //必须
                   success: function (res) { 
                       alert("上传成功！！");
                   },
                   error: function(err){
                	   
                   }
               }) 
           })
       });
/*]]>*/
</script>
</html>
